package com.jinbo.footmessage.setting;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.jinbo.footmessage.BaseActivity;
import com.jinbo.footmessage.MyApplication;
import com.jinbo.footmessage.NavigationActivity;
import com.jinbo.footmessage.R;
import com.jinbo.footmessage.login.LoginActivity;
import com.jinbo.footmessage.utils.ActivitiesHelper;
import com.jinbo.footmessage.utils.DialogUtils;
import com.jinbo.footmessage.utils.LocalPreferencesHelper;
import com.jinbo.footmessage.view.TitleBarView;

public class SettingActivity extends BaseActivity implements View.OnClickListener {
    Button button;
    Boolean isLoginOut=false;
    LinearLayout mModyPasswrodLl;

    public static void launch(Activity activity) {// ,int requestCode) {
        Intent intent = new Intent(activity, SettingActivity.class);
        activity.startActivity(intent);//,requestCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        TitleBarView titleBarView = (TitleBarView) findViewById(R.id.tbv_setting);
        titleBarView.setCenterTitle("设置");
        titleBarView.setLeftBackButtonIsVisibler(true);
        titleBarView.setListener(TitleBarView.TitleBarEnum.ll_leftBackImageLayout, this);
        button = (Button) findViewById(R.id.btn);
        button.setOnClickListener(this);
        mModyPasswrodLl = (LinearLayout) findViewById(R.id.ll_modify_pwd);
        mModyPasswrodLl.setOnClickListener(this);
        // if(!(MyApplication.local.getString(LocalPreferencesHelper.USER_ID).equals("")))
        //     isLogin=true;
        //if(isLogin)
        button.setText("退出当前账号");
        // else
        //    button.setText("请登录");

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_back_layout:
                finish();
                break;
            case R.id.btn:
                isLoginOut=true;
                //  if (isLogin) {
                new DialogUtils(SettingActivity.this, 0, "center", true).setMessage("确定退出登录吗？").setButtons("取消", "确定", new DialogUtils.OnDialogButtonClickListener() {
                    @Override
                    public void onDialogButtonClick(Context context, DialogUtils builder, Dialog dialog, int dialogId, int which) {
                        if (which == DialogUtils.OnDialogButtonClickListener.BUTTON_RIGHT) {
                            //置空
                            // MyApplication.local.saveOrUpdate("user_phone", "");
                            MyApplication.local.del(LocalPreferencesHelper.USER_ID);
                            //  Intent data = new Intent();
                            // data.putExtra("is_logouted", true);
                            // setResult(RESULT_OK, data);
                           // finish();
                            LoginActivity.launch(SettingActivity.this,isLoginOut);
                            finish();
                            ActivitiesHelper.getInstance().closeAll();
                        }
                    }
                }).create().show();

            /*    }
                else
                    LoginActivity.launch(this);*/
                break;
            case R.id.ll_modify_pwd:
                ModifyPwdActivity.launch(this);
                break;
        }
    }
}
